<?php include_once 'header.php';?>
	<div class="row" id="census-rows">
		<div class="col-md-3 mb-3">
			<div class="card shadow">
				<div class="card-body">
					<div class="row align-items-center">
						<div class="col">
							<span class="h3 mb-0" id="kami_num">
								0
							</span>
							<p class="small text-muted mb-0">
								卡密总数
							</p>
						</div>
						<div class="col-auto">
							<span class="fe fe-32 fe-credit-card text-muted mb-0">
							</span>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="col-md-3 mb-3">
			<div class="card shadow">
				<div class="card-body">
					<div class="row align-items-center">
						<div class="col">
							<span class="h3 mb-0" id="kami_use_num">
								0
							</span>
							<p class="small text-muted mb-0">
								已使用数
							</p>
						</div>
						<div class="col-auto">
							<span class="fe fe-32 fe-flag text-muted mb-0">
							</span>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="col-md-3 mb-3">
			<div class="card shadow">
				<div class="card-body">
					<div class="row align-items-center">
						<div class="col">
							<span class="h3 mb-0" id="kami_exp_num">
								0
							</span>
							<p class="small text-muted mb-0">
								已过期数
							</p>
						</div>
						<div class="col-auto">
							<span class="fe fe-32 fe-clock text-muted mb-0">
							</span>
						</div>
					</div>
				</div>
			</div>
		</div>
        <div class="col-md-3 mb-3">
            <div class="card shadow">
                <div class="card-body">
                    <div class="row align-items-center">
                        <div class="col">
							<span class="h3 mb-0" id="kami_online">
								0
							</span>
                            <p class="small text-muted mb-0">
                                在线数量
                            </p>
                        </div>
                        <div class="col-auto">
							<span class="fe fe-32 fe-check text-muted mb-0">
							</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
	</div>

	<div class="row" id="log-rows">
		<div class="col-md-12">
			<div class="card shadow eq-card">
				<div class="card-header">
					<strong class="card-title">
						操作日志
					</strong>
					<a class="float-right small text-muted" href="/admin/logs">
						更多
					</a>
				</div>
				<div class="card-body">
					<div class="p-4" id="logs_state">
						<div class="text-center mt-5 mb-5">
							<div class="avatar avatar-lg">
								<img src="/assets/images/null.png" class="avatar-img" style="width: 100px;">
							</div>
							<div class="card-text">
								<strong class="card-title my-0">
									暂无日志
								</strong>
								<p class="small text-muted mb-5">
									There's a little problem
								</p>
							</div>
						</div>
					</div>
					<div class="table-responsive mb-0">
						<table class="table table-hover table-borderless table-striped" id="table_logs" hidden>
							<thead>
								<tr>
									<th class="wd-20">
										操作类型
									</th>
									<th class="text-left">
										操作人
									</th>
									<th class="wd-20">
										时间/IP
									</th>
									<th class="wd-20">
										状态
									</th>
								</tr>
							</thead>
							<tbody id="tbody_logs">

							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>

	<div class="row" id="server-rows">
		<div class="col-md-12">
			<div class="card shadow">
				<div class="card-header">
					<strong class="card-title">
						服务器信息
					</strong>
				</div>
				<div class="card-body">
					<p>当前版本：<span id="sys_ver" class="mr-2"><?=$this->appConf['SYS_VERSION']?></span><a href="" target="_blank" class="badge badge-pill badge-primary" id="new_ver" hidden>发现新版本</a></p>
					<p>当前域名：<span id="domain">www.user.com</span></p>
					<p>PHP版本：<span id="php_ver">0.0</span></p>
					<p>MySQL版本：<span id="mysql_ver">0.0</span></p>
					<p>服务器环境：<span id="serverapp">null</span></p>
					<p>服务器空间允许上传最大文件：<span id="uploadfile_maxsize">2M</span></p>

				</div>
			</div>
		</div>
	</div>
    <script src="/assets/js/apexcharts.min.js"></script>
	<script>
        function init(act, pg) {
            initAct = act;
            initPg = pg;
            $.ajax({
                cache: false,
                type: "POST",
                data: {
                    act
                },
                dataType: 'json',
                success: function(data) {
                    if (data.code == 200) {
                        census(data.data.census);
                        $("#domain")
                            .html(data.data.census.server_info.domain);
                        $("#php_ver")
                            .html(data.data.census.server_info.php_ver);
                        $("#mysql_ver")
                            .html(data.data.census.server_info.mysql_ver);
                        $("#serverapp")
                            .html(data.data.census.server_info.serverapp);
                        $("#uploadfile_maxsize")
                            .html(data.data.census.server_info.uploadfile_maxsize);
                        loading_end(true, null)
                    } else {
                        loading_end(false, data.msg, true)
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    loading_end(false, textStatus, true)
                }
            });
            return false
        };

        function census(arr) {
            $("#kami_num")
                .html(arr.kami_num);
            $("#kami_use_num")
                .html(arr.kami_use_num);
            $("#kami_exp_num")
                .html(arr.kami_exp_num);
            $("#kami_online").html(arr.kami_online);
            logs(arr.logs)
        };

        function logs(list) {
            if (list.length > 0) {
                $("#table_logs")
                    .attr("hidden", false);
                $("#logs_state")
                    .attr("hidden", true)
            } else {
                $("#logs_state")
                    .attr("hidden", false);
                $("#table_logs")
                    .attr("hidden", true)
            }
            $("#tbody_logs")
                .empty();
            for (var i = 0; i < list.length; i++) {
                var lists = '<tr><td scope="col">' + list[i].actType + '<br /><span class="small text-muted">操作类型</span></td><td class="text-left">' + list[i].actUser + '<br /><span class="small text-muted">' + list[i].actPerson + '</span></td><td>' + list[i].time + '<br /><span class="small text-muted">' + list[i].ip + '</span></td><td><span class="dot dot-lg bg-' + (list[i].state == 'y' ? 'success' : 'danger') + '"></span></td></tr>';
                $("#tbody_logs")
                    .append(lists)
            }
        };
    </script>
<?php include_once 'footer.php';?>
